// 点击颜色样式

$('.m-Hu1 a').click(function () {
    red($('.m-Hu1 a'), $(this));
}).eq(0).click();

function red(pat, e) {
    pat.css('color', '');
    e.css('color', '#eb5151');
}

$('.m-left div,.m-cb').hover(function () {
    $('.m-cb').css('display', 'block');
}, function () {
    $('.m-cb').css('display', '');
});

// ------------------------------------------------------------------------
// 轮播
var index = 0;
var width = parseInt($('.m-cent li').css('width'));
var timer;

// ------------------------------------------------------------------------------------
// 提取ul宽度
$('.m-cent ul').css('width', width * $('.m-cent li').length);

$('.m-cent').hover(function () {
    clearInterval(timer)
}, function () {
    run();
}).mouseout();

function run() {
    timer = setInterval(function () {
        index++;
        if (index > $('.m-cent li').length - 1) {
            index = 0;
        }
        ss();
    }, 3000)
}

function ss() {
    var time = setInterval(function () {
        var off = true;
        var now = parseInt($('.m-cent ul').css('left'));
        var to = -index * width;
        var ss = (to - now) / 6;
        ss > 0 ? ss = Math.ceil(ss) : ss = Math.floor(ss);
        if (now !== to) {
            $('.m-cent ul').css('left', now + ss + 'px');
            off = false;
        }
        if (off) {
            clearInterval(time)
        }
    }, 50);
}

// -------------------------------------------------------------------------------------
//获取滚动条位置
$('.u-to-top').click(function () {
    // toTop()
    goTop()
});

//回到顶部 直接
function toTop() {
    var topL0 = $(".u-to-top").offset().top;
    $(document).scrollTop(0)
}

/**
 * 回到页面顶部 滑动
 * @param acceleration 加速度
 * @param time 时间间隔 (毫秒)
 **/
function goTop(acceleration, time) {
    acceleration = acceleration || 0.1;
    time = time || 16;

    var x1 = 0;
    var y1 = 0;
    var x2 = 0;
    var y2 = 0;
    var x3 = 0;
    var y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }
    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }
    var x3 = window.scrollX || 0;
    var y3 = window.scrollY || 0;

// 滚动条到页面顶部的水平距离
    var x = Math.max(x1, Math.max(x2, x3));
// 滚动条到页面顶部的垂直距离
    var y = Math.max(y1, Math.max(y2, y3));

// 滚动距离 = 目前距离 / 速度, 因为距离原来越小, 速度是大于 1 的数, 所以滚动距离会越来越小
    var speed = 1 + acceleration;
    window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));

// 如果距离不为零, 继续调用迭代本函数
    if (x > 0 || y > 0) {
        var invokeFunction = "goTop(" + acceleration + ", " + time + ")";
        window.setTimeout(invokeFunction, time);
    }
}

// --------------------------------------------------------------------------------------------
// 获取浏览器窗口高度
$(window).resize(function () {
    var s = document.body.clientHeight;
    $('.m-dv').css('margin-top', s / 3)
}).resize();

// ------------------------------------------------------------------------------------------------
//页码
/*

 function ss(obj) {
 function yema(curr, d, z) {
 var src = '';
 if (z <= 7) {
 if (d != 1) {
 src += '<span>上一页</span>'
 }
 for (var i = 1; i <= z; i++) {
 if (i == d) {
 src += '<span class="' + curr + '">' + i + '</span>'
 } else {
 src += '<span>' + i + '</span>'
 }
 }
 if (d != z) {
 src += '<span>下一页</span>'
 }
 } else {
 if (d != 1) {
 src += '<span>上一页</span>'
 }
 if (d <= 4) {
 for (var i = 1; i <= 6; i++) {
 if (i == d) {
 src += '<span class="' + curr + '">' + i + '</span>'
 } else {
 src += '<span>' + i + '</span>'
 }
 }
 src += '<b>...</b><span>' + z + '</span>'
 }
 if (d > z - 4) {
 src += '<span>1</span><b>...</b>';
 for (var i = z - 5; i <= z; i++) {
 if (i == d) {
 src += '<span class="' + curr + '">' + i + '</span>'
 } else {
 src += '<span>' + i + '</span>'
 }
 }
 }
 if (d > 4 && d < z - 3) {
 src += '<span>1</span><b>...</b>';
 for (var i = d - 2; i < d + 3; i++) {
 if (i == d) {
 src += '<span class="' + curr + '">' + i + '</span>'
 } else {
 src += '<span>' + i + '</span>'
 }
 }
 src += '<b>...</b><span>' + z + '</span>'
 }
 if (d != z) {
 src += '<span>下一页</span>';
 }
 }
 obj.element.html(src);
 }

 obj.ajaxPage(1, yema);
 obj.element.on('click', 'span', function () {
 var num = Number($(this).siblings(obj.pageClass).html());
 if ($(this).html() == '上一页') {
 num--;
 } else if ($(this).html() == '下一页') {
 num++;
 } else {
 num = Number($(this).html());
 }
 obj.ajaxPage(num, yema)
 })
 }
 */

$('.u-paixu').click(function () {
    if ($(this).children('i').hasClass('icon-xiajiantou')) {
        $(this).children('i').removeClass('icon-xiajiantou').addClass('icon-icon22')
    } else {
        $(this).children('i').removeClass('icon-icon22').addClass('icon-xiajiantou')
    }
});


$('.u-zuo').click(function () {
    var ss=parseInt($('.u-nowPage').html());
   if(ss>1){
       ss--;
   }
    $('.u-nowPage').html(ss);
});
$('.u-you').click(function () {
    var ss=parseInt($('.u-nowPage').html());
    var ff=parseInt($('.u-allPage').html());
    if(ss<ff){
        ss++;
    }
    $('.u-nowPage').html(ss);
});


// -----------------------------------------------------------------------------------
